from sqlalchemy import create_engine
engine = create_engine('sqlite:///db1', echo=True)

from sqlalchemy.orm import declarative_base
Base = declarative_base()




def get_session():
    from sqlalchemy.orm import sessionmaker
    Session = sessionmaker(bind=engine)
    session = Session()# 实例化
    return session

session=get_session()


from sqlalchemy import Column, Integer, String
class User(Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True)
    name = Column(String(20))
    password = Column(String(20))
    nickname = Column(String(20))

    def __repr__(self):
        return "<User(name='%s', nickname='%s')>" % (
                             self.name, self.nickname)

class Question(Base):
    __tablename__ = 'question'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    detail = Column(String)



def test():
    user1 = User(name='zkl', nickname='dd', password='轮回中唤我真名者方得永恩')

    session.add(user1)
    session.commit()




if __name__ == "__main__":
    #Base.metadata.create_all(bind=engine)
    test()